package com.sync.syncmasterdata.product.service.convert;

import com.sync.syncmasterdata.product.pojo.cp.InventoryForCP;
import com.sync.syncmasterdata.product.pojo.oa.InventoryForOA;
import com.sync.syncmasterdata.product.service.ConvertInterface;
import org.springframework.stereotype.Service;

/**
 * oa产品对象 转cp产品对象
 */
@Service
public class ProductOAtoCP implements ConvertInterface<InventoryForOA, InventoryForCP> {

    @Override
    public InventoryForCP convertTo(InventoryForOA oa) {
        InventoryForCP cp = new InventoryForCP();
        cp.setTongyongmc(oa.getTongyongmc());
        cp.setKuwei(oa.getKuwei());
        cp.setChanpinlx(oa.getChanpinlx());
        cp.setCunhuobm(oa.getCunhuobm());
        cp.setChanpinmc(oa.getChanpinmc());
        cp.setHuohao(oa.getHuohao());
        cp.setGuigexh(oa.getGuigexh());
        cp.setZhujildw(oa.getZhujildw());
        cp.setJiliangdwwb(oa.getUnitName());    //计量单位文本
        cp.setPinpaiwb(oa.getPinpaiwb());
        cp.setShengchanqy(oa.getShengchanqy());
        cp.setShengchanqywb(oa.getShengchanqywb());
        cp.setShifoucgbh(integerToBool(oa.getShifoucgbh()));
        cp.setJiancexmh(oa.getJiancexmh());

        //需转换
        cp.setGuochanjk(covguochanpp(oa.getGuochanjk()));
        cp.setYewulx(oa.getYewulx());
        cp.setChanpinx(oa.getChanpinx());
        cp.setChanpinz(oa.getChanpinz());
        cp.setXiangmumc(oa.getXiangmumc());
        cp.setXiangmumcwb(oa.getXiangmumcwb());
        cp.setBeizhu(oa.getBeizhu());
        cp.setShifouylqx(covshifouylqx(oa.getShifouylqx()));
        //药监专用
        cp.setShifoucw(integerToBool(oa.getShifoucw()));
        cp.setTingshou(integerToBool(oa.getTingshou()));
        cp.setWenduc(oa.getWenduc());
        cp.setWenduz(oa.getWenduz());
        cp.setYujingyxq(oa.getYujingyxq());
        cp.setYouxiaoq(oa.getYouxiaoq());
        cp.setYanghulx(covyanghulx(oa.getYanghulx()));
        return cp;
    }


    /**
     * 更新用 转换
     * @param oa
     * @return
     */
    public InventoryForCP convertToForUpdate(InventoryForOA oa) {
        InventoryForCP cp = new InventoryForCP();
        cp.setId(oa.getCpid());
        cp.setTongyongmc(oa.getTongyongmc());
        cp.setKuwei(oa.getKuwei());
        cp.setCunhuobm(oa.getCunhuobm());
        cp.setChanpinmc(oa.getChanpinmc());
        cp.setHuohao(oa.getHuohao());
        cp.setGuigexh(oa.getGuigexh());
        cp.setPinpaiwb(oa.getPinpaiwb());
        cp.setShengchanqy(oa.getShengchanqy());
        cp.setShengchanqywb(oa.getShengchanqywb());
        cp.setShifoucgbh(integerToBool(oa.getShifoucgbh()));
        cp.setShifouylqx(covshifouylqx(oa.getShifouylqx()));
        //增加检测项目号 的更新
        cp.setJiancexmh(oa.getJiancexmh());
        return cp;
    }

    /**
     * 转换国产 进口
     */
    private String covguochanpp(int i) {
        try {
            if (i == 0) {
                return "国产";
            } else {
                return "进口";
            }
        } catch (Exception e) {
//            e.printStackTrace();
            return "进口";
        }

    }
    /**
     * 是否医疗器械转换
     * @param i
     * @return
     */
    private boolean covshifouylqx(int i) {
        try {
            if(i==0){
                return false;
            }else{
                return true;
            }
        } catch (Exception e) {
//            e.printStackTrace();
            return true;
        }

    }

    /**
     * 是否常温转换——是否停售 转换 0=否 1=是
     * @param i
     * @return
     */
    private boolean integerToBool(Integer i) {
        try {
            if(i==1){
                return true;
            }else{
                return false;
            }
        } catch (Exception e) {
//            e.printStackTrace();
            return false;
        }
    }

    /**
     * 养护类型转换
     * @param i
     * @return
     */
    private String covyanghulx(Integer i) {
        try {
            if (i == null) {
                return "";
            } else if (i == 1) {
                return "重点养护";
            } else if (i == 2) {
                return "一般养护";
            }else{
                return "一般养护";
            }

        } catch (Exception e) {
//            e.printStackTrace();
            return "一般养护";
        }
    }
}
